import uniqueId from "@form-create/utils/lib/unique";
import {
  localeProps,
  makeOptionsRule,
  makeRequiredRule,
} from "../../utils/index";

const label = "级联选择器";
const name = "cascader";

export default {
  icon: "icon-cascader",
  label,
  name,
  rule({ t }) {
    const opt = t("props.option");
    return {
      type: name,
      field: uniqueId(),
      title: t("components.cascader.name"),
      info: "",
      effect: {
        fetch: "",
      },
      $required: false,
      props: {
        options: [1, 2].map((value) => {
          return {
            label: opt + value,
            value,
            children: [],
          };
        }),
      },
    };
  },
  props(_, { t }) {
    return localeProps(t, name + ".props", [
      makeRequiredRule(),
      makeOptionsRule(t, "props.options", false),
      {
        type: "input",
        field: "placeholder",
        title: "输入框提示文字",
      },
      {
        type: "switch",
        field: "multiple",
        title: "是否多选",
      },
      {
        type: "switch",
        field: "allowSearch",
        title: "是否允许搜索",
      },
      {
        type: "switch",
        field: "checkStrictly",
        title: "是否严格的遵守父子节点不互相关联",
      },
      {
        type: "input",
        field: "value",
        title: "指定选项的值为选项对象的某个属性值",
        value: "value",
      },
      {
        type: "input",
        field: "label",
        title: "指定选项标签为选项对象的某个属性值",
        value: "label",
      },
      {
        type: "input",
        field: "children",
        title: "指定选项的子选项为选项对象的某个属性值",
        value: "children",
      },
      {
        type: "input",
        field: "disabled",
        title: "指定选项的禁用为选项对象的某个属性值",
        value: "disabled",
      },
      {
        type: "input",
        field: "leaf",
        title: "指定选项的叶子节点的标志位为选项对象的某个属性值",
      },
      {
        type: "switch",
        field: "allowClear",
        title: "是否支持清空选项",
      },
      {
        type: "switch",
        field: "disabled",
        title: "是否禁用",
      },
    ]);
  },
};
